<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="common/layout">
<head>
    <title>店铺管理</title>
</head>

<body>
<section layout:fragment="top_menu" style="text-align: left;padding-left: 20px">
    <span style="font-size: 20px">店铺列表</span>
</section>
<section layout:fragment="content">
    <div class="list" style="font-size:0.9em;">
        <table id="list">
            <tr class="header">
                <td>序号</td>
                <td>名称</td>
                <td>店长</td>
                <td>描述</td>
                <td>图片</td>
                <td>操作</td>
            </tr>
            <tbody id="list_body">
            <tr th:each="item,row:${rows}" th:id="${#strings.concat('item_', item.id)}" th:class="${#strings.concat('item_', row.index%2)}">
                <td th:text="${row.index+1}"></td>
                <td>
                    <a th:href="@{/admin/store/mine/{id}(id=${item.id})}" th:text="${item.name}"></a>
                </td>
                <td th:text="${item.owner}"></td>
                <td th:text="${item.description}" class="summary" style="max-width: 100px"></td>
                <td>
                    <img th:if="${item.logoUrl}" th:src="${item.logoUrl}" width="30" height="30" style="border-radius:50%;">
                    <img th:unless="${item.logoUrl}" src="/img/avatar.png" width="30" height="30" style="border-radius:50%;">
                </td>
                <td>
                    <a class="icon-remove" th:href="${#strings.concat('javascript:storeRemove(',item.id, ')')}">删除</a>
                    &nbsp;&nbsp;
                    <a class="icon-edit" th:href="${#strings.concat('/admin/store/edit/',item.id)}">编辑</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="paginator">
            <ul>
                <li><</li>
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li class="dot">...</li>
                <li>9</li>
                <li>></li>
            </ul>
        </div>
    </div>
</section>

<section layout:fragment="extra_scripts">
    <script src="/js/bower_components/bootpag/lib/jquery.bootpag.js"></script>
    <script src="/js/paginator.js"></script>

    <script th:inline="javascript">
        $(function(){
            Paginator.init(
                    [[${total}]],
                    function(page){
                        var querys={};
                        querys["page"] = page;
                        if([[${key_word}]]){
                            querys["key_word"] = [[${stat_key}]];
                        }
                        var url = "/admin/store?" + $.param(querys);
                        self.location.href = url;
                    },
                    [[${page}]]
            );
        });

        function storeRemove(store_id) {
            if (!confirm("确定删除吗？")) {
                return;
            }
            $.post("/admin/store/" + store_id, {_method: "DELETE"}, function (data) {
                if (data.success) {
                    self.location.reload();
                } else {
                    alert(data.message);
                }
            });
        };
    </script>
</section>

</body>

</html>
